package com.example.tvmatchddemo.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.tvmatchddemo.R;
import com.example.tvmatchddemo.base.BaseFragment;
import com.example.tvmatchddemo.border.FocusBorder;


/**
 * Created by dasu on 2017/4/20.
 * <p>
 * 各类型干货的数据展示界面，
 */

public class WoxiuFragment extends BaseFragment {
    //失败方案-----------放大遮挡
    private static final String TAG = WoxiuFragment.class.getSimpleName();
    private TextView textView;
    private TextView tv_right;
    private TextView tv_mind;

    public WoxiuFragment() {
    }

    private Context mContext;


    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.mContext = context;
//        DebugLog.d(LOG+TAG + " ---- onAttach");

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        DebugLog.d(LOG+TAG + " ---- onCreate");
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        DebugLog.d(LOG+TAG + " ---- onCreateView");
        View view = inflater.inflate(R.layout.fragment_woxiu, container, false);
        initView(view);
        return view;
    }


    private void initView(View view) {
        textView = view.findViewById(R.id.tv_left);
        tv_right = view.findViewById(R.id.tv_right);
        tv_mind = view.findViewById(R.id.tv_mind);
        //焦点监听 方式一:绑定整个页面的焦点监听事件
        mColorFocusBorder.boundGlobalFocusListener(new FocusBorder.OnFocusCallback() {
            @Override
            public FocusBorder.Options onFocus(View oldFocus, View newFocus) {
                if(null != newFocus) {
                    switch (newFocus.getId()) {
                        case R.id.tv_2:
                        case R.id.tv_3:
                        case R.id.tv_4:
                            return  createColorBorderOptions(0);
                        default:
                            break;
                    }
                }
                mColorFocusBorder.setVisible(false);
                //返回null表示不使用焦点框框架
                return null;
            }
        });
//        textView.getViewTreeObserver().addOnGlobalFocusChangeListener(new ViewTreeObserver.OnGlobalFocusChangeListener() {
//            @Override
//            public void onGlobalFocusChanged(View oldFocus, View newFocus) {
////                if(newFocus instanceof FrameLayout && newFocus.getParent() instanceof GridLayout){
//                    newFocus.bringToFront();
////                }
//            }
//        });
        textView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    textView.bringToFront();
                }
            }
        });
        tv_right.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    tv_right.bringToFront();
                }
            }
        });
        tv_mind.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    tv_mind.bringToFront();
                }
            }
        });
        mDrawableFocusBorder.boundGlobalFocusListener(new FocusBorder.OnFocusCallback() {
            @Override
            public FocusBorder.Options onFocus(View oldFocus, View newFocus) {
                if(null != newFocus) {
                    switch (newFocus.getId()) {
                        case R.id.tv_right:
                        case R.id.tv_left:
                        case R.id.tv_mind:
                            return  createDrawableFocusBorder(0);
                        default:
                            break;
                    }
                }
                mDrawableFocusBorder.setVisible(false);
                //返回null表示不使用焦点框框架
                return null;
            }
        });


    }


    @Override
    protected void onFragmentVisibleChange(boolean isVisible) {

    }

    @Override
    protected void onFragmentFirstVisible() {

    }

}
